<?php
namespace Home\Controller;
use Think\Controller;
class DetailController extends CommonController{
    
    public function index(){
       $id=intval($_GET['id']); 
       if(!$id || $id<0){
           return $this->error("Id不合法");
       }
       $news=D('News')->find($id);
       //验证新闻是否合法
       if(!$news || $news['status'] !=1){
          return $this->error("资讯被关闭或新闻数据不合法"); 
       }
       //
       $count= intval($news['count'])+1;
       D("News")->updateCount($id,$count);
       
       $content=D('NewsContent')->find($id);
       $news['content']=htmlspecialchars_decode($content['content']);
       $advNews=D("PositionContent")->select(array('status'=>1,'position_id'=>5),2);
       $rankNews=$this->getRank();
       $this->assign('result',array(
         'advNews'=>$advNews,
         'rankNews'=>$rankNews,
          'catId'=>$news['catid'],
          'news'=>$news 
           
       ));
       $this->display('Detail/index');
    }
     public function view() {
        if(!getLoginUsername()) {
            $this->error("您没有权限访问该页面");
        }
        $this->index();

    }
}
